package com.project.genesis.oss.controller;


import com.project.genesis.common.result.Result;
import com.project.genesis.oss.service.FileInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.UnknownHostException;

/**
 * <p>
 * 文件信息表 前端控制器
 * </p>
 *
 * @author qtx
 * @since 2022-09-26
 */
@Api(tags = "文件")
@RestController
@RequestMapping("/oss/fileInfo")
public class FileInfoController {

    @Autowired
    private FileInfoService service;

    @ApiOperation("获取文件")
    @GetMapping("/getPlay")
    public void getPlay(@RequestParam
                        String uuid, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        service.getPlay(uuid, request, response);
    }

    @ApiOperation("新建上传文件")
    @PostMapping("/saveNewUpload")
    public Result<Object> saveNewUpload(MultipartFile file, HttpServletRequest request, String uuid,
                                        @RequestParam String otherId) throws UnknownHostException {
        return Result.ok(service.saveNew(file, request, uuid, otherId));
    }
}
